def parse_user_agent(ua_string):
    """
    解析User-Agent字符串，返回浏览器和操作系统信息
    """
    ua_string = ua_string.lower()
    user_agent = {
        'browser': 'Unknown',
        'os': 'Unknown',
        'device_type': 'desktop'
    }
    
    # 检测浏览器
    browsers = {
        'chrome': 'Chrome',
        'firefox': 'Firefox',
        'safari': 'Safari',
        'edge': 'Edge',
        'opera': 'Opera',
        'msie': 'Internet Explorer'
    }
    
    for key, value in browsers.items():
        if key in ua_string:
            user_agent['browser'] = value
            break
    
    # 检测操作系统
    if 'windows' in ua_string:
        user_agent['os'] = 'Windows'
    elif 'mac' in ua_string:
        user_agent['os'] = 'MacOS'
    elif 'linux' in ua_string:
        user_agent['os'] = 'Linux'
    elif 'android' in ua_string:
        user_agent['os'] = 'Android'
        user_agent['device_type'] = 'mobile'
    elif 'iphone' in ua_string or 'ipad' in ua_string:
        user_agent['os'] = 'iOS'
        user_agent['device_type'] = 'mobile'
    
    return user_agent
